<script setup lang="ts">
import ReCol from "@/components/ReCol";
import { ref } from "vue";
import { FormProps } from "./utils/types";

const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    wa_account: "",
    admin_user_id: undefined,
    remark: "",
    is_drainage: false,
    status: 1,
    userList: []
  })
});

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}

defineExpose({ getRef });

const formRules = {
  wa_account: [
    { required: true, message: "WhatsApp账号不能为空", trigger: "blur" },
    { min: 3, max: 50, message: "账号长度应在3-50个字符", trigger: "blur" }
  ],
  admin_user_id: [
    { required: true, message: "使用者不能为空", trigger: "change" }
  ]
};
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    :rules="formRules"
    label-width="100px"
  >
    <el-row :gutter="30">
      <re-col :value="24" :xs="24" :sm="24">
        <el-form-item label="账号" prop="wa_account">
          <el-input
            v-model="newFormInline.wa_account"
            clearable
            placeholder="请输入WhatsApp账号"
            style="width: 100%"
          />
        </el-form-item>
      </re-col>

      <re-col :value="24" :xs="24" :sm="24">
        <el-form-item label="使用者" prop="admin_user_id">
          <el-select
            v-model="newFormInline.admin_user_id"
            placeholder="请选择使用者"
            clearable filterable
            style="width: 100%"
          >
            <el-option
              v-for="user in newFormInline.userList"
              :key="user.id"
              :label="user.name"
              :value="user.id"
            />
          </el-select>
        </el-form-item>
      </re-col>

      <re-col :value="24" :xs="24" :sm="24">
        <el-form-item label="备注" prop="remark">
          <el-input
            v-model="newFormInline.remark"
            :rows="3"
            type="textarea"
            placeholder="请输入备注信息"
            style="width: 100%"
          />
        </el-form-item>
      </re-col>

      <re-col :value="24" :xs="24" :sm="24">
        <el-form-item label="账号状态" prop="status">
          <el-select
            v-model="newFormInline.status"
            placeholder="请选择状态"
            style="width: 100%"
          >
            <el-option :key="1" label="正常" :value="1" />
            <el-option :key="0" label="停用" :value="0" />
          </el-select>
        </el-form-item>
      </re-col>

      <re-col :value="24" :xs="24" :sm="24">
        <el-form-item label="用于引流" prop="is_drainage">
          <el-checkbox
            v-model="newFormInline.is_drainage"
          >
          <div style="color: #909399; font-size: 12px; margin-top: 4px;">
            勾选后，该账号将自动添加到使用者的WhatsApp引流账号列表中
          </div>
          </el-checkbox>
          
        </el-form-item>
      </re-col>
    </el-row>
  </el-form>
</template> 